package com.hmall.order.utils;

public class ThreadLocalUtil {
    private static ThreadLocal<Long> THREAD_LOCAL = new ThreadLocal<>();
    /**
     * 设置值
     * @param id
     */
    public static void setCurrentId(Long id){
        THREAD_LOCAL.set(id);
    }
    /**
     * 获取值
     * @return
     */
    public static Long getCurrentId(){
        return THREAD_LOCAL.get();
    }

    /**
     * 线程结束threadLocal中的值需要remove,并不会随线程结束被JVM回收
     * 可以在过滤器的doFilter后执行remove操作
     * 使用完，移除取值
     * @return
     */
    public static void removeCurrentId(){
        THREAD_LOCAL.remove();
    }
}
